import axios from 'axios';
import qs from 'querystring';

export const getUpdate = () => {
  return axios.get('/api/system/getUpdate');
};

export const getPackageInfo = () => {
  return axios.get('/api/system/getPackageInfo');
};

export const getInterfaces = () => {
  return axios.get('/api/system/scanInterface');
};

// 单机节点接口废弃
export const modUpdate = body => {
  return axios.post('/api/system/modUpdate', body);
};

export const uploadPackage = (body, config) => {
  return axios.post('/api/system/uploadPackage', body, config);
};

export const uploadClanPackage = (body, config) => {
  return axios.post('/api/cluster/upload/package', body, config);
};

export const upgrade = params => {
  return axios.get(`/api/system/upgrade?${qs.stringify(params)}`);
};

export const clusterUpgrade = body => {
  return axios.post('/api/cluster/upgrade', body);
};

export const getUpgradeState = () => {
  return axios.get('/api/ksp/upgrade');
};

export const operateDevice = body => {
  return axios.post('/api/system/operateDevice', body);
};

// 获取资源库升级信息
export const resourceInfo = () => {
  return axios.get('/api/resource/info');
};

// 配置系统资源库升级方式
export const resourceModify = body => {
  return axios.post('/api/resource/upgrade/modify', body);
};

// 上传资源库
export const resourcUpload = (body, config) => {
  return axios.post('/api/resource/upload', body, config);
};

// 触发升级
export const upgradeStart = body => {
  return axios.post('/api/resource/upgrade/start', body);
};

// 取消升级
export const cancelUpgrade = body => {
  return axios.post('/api/resource/upgrade/cancel', body);
};

// 单机接口废弃
// 获取升级状态
export const upgradeStatust = () => {
  return axios.get('/api/resource/upgrade/status');
};

// 获取升级进度状态(集群)
export const getClusterUpgradeStatust = params => {
  return axios.get(`/api/cluster/upload/status?${qs.stringify(params)}`);
};

// 获取自动升级状态(集群)
export const getClusterAutoUpdate = params => {
  return axios.get(`/api/cluster/autoUpdate/status?${qs.stringify(params)}`);
};

//触发自动系统升级(集群)
export const clusterAutoUpdate = body => {
  return axios.post('/api/cluster/autoUpdate/setting', body);
};

//取消系统升级
export const cancelSystemUpgrade = body => {
  return axios.post('/api/system/upgrade/cancel', body);
};

export const getUpgradeUpdate = () => {
  return axios.get('/api/ksp/cluster/upgrade');
};
